<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%- include ../taglibs/layout_head.ejs%>
    <%- include ../taglibs/layout.css.ejs%>
    <link href="js/plugins/zTree/css/metroStyle/metroStyle.css" rel="stylesheet">
    <script type="text/javascript">
        String.prototype.replaceAll = function (reallyDo, replaceWith) {
            return this.replace(new RegExp(reallyDo, ("gm")), replaceWith);
        };
        var parentMenuList = '<%= parentMenuList%>';
        var  sysMap = '<%= sysMap%>';
        var _parentMenuList,
            _sysMap;
        if(parentMenuList !="false"){
            if(parentMenuList.indexOf("&quot;") != -1){
                _parentMenuList = parentMenuList.replaceAll("&quot;", "\"");
            }else if(parentMenuList.indexOf("&#34;") != -1){
                _parentMenuList = parentMenuList.replaceAll("&#34;", "\"");
            }
            window.sessionStorage.setItem("rootMenus",_parentMenuList);
        }
        if(sysMap !="false"){
            if(sysMap.indexOf("&quot;") != -1){
                _sysMap = sysMap.replaceAll("&quot;", "\"");
            }else if(sysMap.indexOf("&#34;") != -1){
                _sysMap = sysMap.replaceAll("&#34;", "\"");
            }
            window.sessionStorage.setItem("chidlMenus",_sysMap)
        }
    </script>
</head>
<body>
<%-include("../taglibs/header.ejs",{params:{className:"active",dataIsActive:"true"}})%>
<div class="nav-body" id="divContent">
    <div class="nav-box">
        <div class="row">
            <div class="col-sm-4 col-md-3 col-lg-2 nav-box-left-box">
                <%-include("dataManageLeftMenu.ejs",{params:{className:"active",roleManage:"true"}})%>
            </div>
            <div class="col-sm-6 col-md-9 col-lg-10 right-container-box">
                <div class="right-container">
                    <section class="content content-search">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="col-sm-12 col-md-10">
                                    <div class="col-sm-12 col-md-12 content-search-left">
                                        <input type="text" id="deptId" name="deptId" hidden="hidden">
                                        <div class="col-sm-12 col-md-6 col-lg-4 content-search-left-box">
                                            <label class="col-sm-4">
                                                角色名称：
                                            </label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" id="roleName" name="roleName">
                                            </div>
                                        </div>
                                        <!--<div class="col-sm-12 col-md-6 col-lg-4 content-search-left-box">
                                            <label class="col-sm-4">
                                                所属用户：
                                            </label>
                                            <div class="col-sm-8">
                                                <input type="email" class="form-control" id="deptName" name="deptName" style="padding-right: 54px" readonly="readonly">
                                                <button type="button" class="btn btn-theme selectUser"
                                                        style="position: absolute;top: 0px;right: 0px;">选择</button>
                                            </div>
                                        </div>-->
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-2 " style="text-align: center">
                                    <button type="button" id="dosearch" class="btn btn-round btn-theme" style="margin-bottom: 3px;margin-top: 3px">查 询</button>
                                    <button type="button" id="resetForm" class="btn btn-round btn-danger" style="margin-bottom: 3px;margin-top: 3px">重 置</button>
                                </div>
                            </div>
                        </div>
                    </section>
                    <section class="content content-table">
                        <!--<section class="content-table-tools">
                            <div class="tools-box">
                                <button type="button" class="btn btn-round btn-add">新 增</button>
                                <button type="button" class="btn btn-round btn-danger">删 除</button>
                            </div>
                        </section>-->
                        <div style="display: block">
                            <div id="toolbar" class="btn-group">
                                <button id="btn_add" type="button" op_resId="16_40" class="btn btn-default dp-none">
                                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                                </button>
                                <!--<button id="btn_edit" type="button" class="btn btn-default">-->
                                    <!--<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改-->
                                <!--</button>-->
                                <button  type="button" op_resId="16_42" class="btn btn-default dp-none" onclick="deleteRoleRows()">
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
                                </button>
                            </div>
                            <table id="roleTable"></table>
                        </div>
                    </section>
                </div>
            </div>
        </div>

    </div>
</div>
<div class="modal fade" id="myTreeDialog">
    <div class="modal-dialog" style="width: 320px;">
        <div class="modal-content" style="width: 320px;">
            <div class="modal-header">
                <button type="button" class="close" onclick="closeTreeDialog()">×</button>
                <h4 class="modal-title" id="NoPermissionModalLabel">所属上级</h4>
            </div>
            <div class="modal-body" style="height:320px;max-height:320px;max-width: 320px;
                overflow: auto;">
                <ul id="userCommonTree" class="ztree">
                </ul>
            </div>
            <div class="modal-footer">
                <button class="btn btn-info"   type="button" onclick="getAllCheckNodes()">确 定</button>
            </div>
        </div>
    </div>
</div>
<%-include ../taglibs/layout.js.ejs%>
<script type="text/javascript" src="js/common/role_auth_com.js"></script>
<script src="/js/plugins/zTree/js/jquery.ztree.all-3.5.js"></script>
<script src="/js/plugins/zTree/js/jquery.ztree.exhide-3.5.js"></script>
<!--<script src="/js/ztree/ztree-cus-table.js"></script>-->
<script src="/js/ztree/ztree-cus-check.js"></script>
<script src="/js/ztree/ztree-user.js"></script>
<script type="text/javascript" src="js/viewpage/dataManage/dataManage.js"></script>
<script type="text/javascript" src="js/viewpage/dataManage/role/role.js"></script>
<script type="text/javascript">
    var url = '/tree/dept';
    $(function () {
        RoleInfo.initRolePage();
        UserTreeComponents.initUserTree('id', 'parentId', 'name',clickTree,treeCheck, "radio");
        UserTreeComponents.loadUserTree(url,"userCommonTree")
    })
    function clickTree(event, treeId, treeNode) {
//        debugger;
//        var flag=treeNode.checked;
//        tree_Obj.checkNode(treeNode, true, true);
//        selectTreeNode(treeNode);
    }
    function treeCheck(event, treeId, treeNode, clickFlag) {

    }
    function closeTreeDialog() {
        $("#myTreeDialog").modal("hide");
    }
    function getAllCheckNodes() {
        var node = userTreeObj.getCheckedNodes(true)[0];
        if(node){
            $("#deptName").val(node.name);
            $("#kindId").val(node.id);
        }else{
            $("#deptName").val("");
            $("#kindId").val("");
        }
        closeTreeDialog();
    }
    function deleteRoleRow(id) {
        if(id == "1"){
            $.messageExt.alert("系统提示","管理员角色不能删除！","warning");
            return false
        }
        $.ajax({
            type: "POST",
            url: "/roleManage/deleteRole",
            async: true,
            dataType: "json",
            data:{ids:id},
            success: function (data) {
                $.messageExt.alert("系统提示","删除成功！","success");
                roleDataTable.refresh();
            }
        });
    }
    function deleteRoleRows() {
        var selectRows = roleDataTable.getSelections();
        if(!selectRows.length){
            $.messageExt.alert("系统提示","请先选择数据！","warning")
            return false
        }

        var ids = [];
        var isRootRole = false;
        $.each(selectRows,function (index,row) {
            if(row.id == "1"){
                isRootRole = true;
            }
            ids.push(row.id);
        })
        if(isRootRole){
            $.messageExt.alert("系统提示","管理员角色不能删除！","warning");
            return false
        }
        $.ajax({
            type: "POST",
            url: "/roleManage/deleteRole",
            async: true,
            dataType: "json",
            data:{ids:ids.toString()},
            success: function (data) {
                $.messageExt.alert("系统提示","删除成功！","success");
                roleDataTable.refresh();
            }
        });
    }
</script>
</body>
</html>